CONTENTS | INDEX | PREV | NEXT
strrchr
NAME
strrchr - search for a character in a string, scan backwards
SYNOPSIS
char *ptr = strrchr(s, c)
const char *s;
int c;
FUNCTION
Searches for the character c within the string pointed to by
s. The terminating nul at the end of s is included in the search.
The string is searched backwards
A pointer to the LAST occurance of c in s is returned or NULL
if c could not be found.
c is converted to an 8 bit quantity by strrchr().
NOTE
The ANSI spec does not say anything about including the nul
character in the search for strrchr and some implementation
may thus not implement this properly.
EXAMPLE
#include <stdio.h>
#include <string.h>
#include <assert.h>
main()
{
char *s = "this is a test";
char *ptr;
ptr = strrchr(s, 'i');
assert(ptr == s + 5);
puts(ptr); /* "is a test" */
ptr = strrchr(s, 'x');
assert(ptr == NULL);
return(0);
}
INPUTS
char *s; pointer to the string to search
int c; character to search for
RESULTS
char *ptr; pointer to the last occurance of character c in
s or NULL if c could not be found in s.
SEE ALSO
strchr